home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_337 / cmanual / menus.lzh / Menus / Example2.c < prev    next >
C/C++ Source or Header  |  1990-01-30  |  16KB  |  409 lines

  1. /* Example2                                                             */
  2. /* This program opens a normal window to which we connect a menu strip. */
  3. /* The menu will look like this:                                        */
  4. /*                                                                      */
  5. /* Edit                                                                 */
  6. /* ----------                                                           */
  7. /* | Style -----------------                                            */
  8. /* --------| v Plain       |                                            */
  9. /*         |   Bold        |                                            */
  10. /*         |   Underlined  |                                            */
  11. /*         |   Italic      |                                            */
  12. /*         -----------------                                            */
  13. /*                                                                      */
  14. /* This example is very similar to Example1, but we have this time put  */
  15. /* the edit styles in a subitem box which is connected to the one and   */
  16. /* only item box called "Style"                                         */
  17.  
  18.  
  19.  
  20. #include <intuition/intuition.h>
  21.  
  22.  
  23.  
  24. struct IntuitionBase *IntuitionBase;
  25.  
  26.  
  27.  
  28. /*************************************************************************/
  29. /*                      F O U R T H   S U B I T E M                      */
  30. /*************************************************************************/
  31.  
  32. /* The text for the fourth subitem: */
  33. struct IntuiText my_fourth_text=
  34. {
  35.   2,            /* FrontPen, black. */
  36.   0,            /* BackPen, not used since JAM1. */
  37.   JAM1,         /* DrawMode, do not change the background. */
  38.   CHECKWIDTH,   /* LeftEdge, CHECKWIDTH amount of pixels out. */
  39.                 /* This will leave enough space for the check mark. */
  40.   1,            /* TopEdge, 1 line down. */
  41.   NULL,         /* TextAttr, default font. */
  42.   "Italic",     /* IText, the string. */
  43.   NULL          /* NextItem, no link to other IntuiText structures. */
  44. };
  45.  
  46. /* The MenuItem structure for the fourth subitem: */
  47. struct MenuItem my_fourth_subitem=
  48. {
  49.   NULL,            /* NextItem, this is the last subitem in the list. */
  50.   50,              /* LeftEdge, 50 pixels out. */
  51.   35,              /* TopEdge, 35 lines down. */
  52.   150,             /* Width, 150 pixels wide. */
  53.   10,              /* Height, 10 lines high. */
  54.   ITEMTEXT|        /* Flags, render this item with text. */
  55.   ITEMENABLED|     /*        this item will be enabled. */
  56.   CHECKIT|         /*        it is an attribute item. */
  57.   HIGHCOMP,        /*        complement the colours when highlihted. */
  58.   0x00000001,      /* MutualExclude, mutualexclude the first subitem. */
  59.   (APTR) &my_fourth_text, /* ItemFill, pointer to the text. */
  60.   NULL,            /* SelectFill, nothing since we complement the col. */
  61.   0,               /* Command, no command-key sequence. */
  62.   NULL,            /* SubItem, ignored by Intuition. */
  63.   MENUNULL,        /* NextSelect, no items selected. */
  64. };
  65.  
  66.  
  67.  
  68. /*************************************************************************/
  69. /*                       T H I R D   S U B I T E M                       */
  70. /*************************************************************************/
  71.  
  72. /* The text for the third subitem: */
  73. struct IntuiText my_third_text=
  74. {
  75.   2,            /* FrontPen, black. */
  76.   0,            /* BackPen, not used since JAM1. */
  77.   JAM1,         /* DrawMode, do not change the background. */
  78.   CHECKWIDTH,   /* LeftEdge, CHECKWIDTH amount of pixels out. */
  79.                 /* This will leave enough space for the check mark. */
  80.   1,            /* TopEdge, 1 line down. */
  81.   NULL,         /* TextAttr, default font. */
  82.   "Underlined", /* IText, the string. */
  83.   NULL          /* NextItem, no link to other IntuiText structures. */
  84. };
  85.  
  86. /* The MenuItem structure for the third subitem: */
  87. struct MenuItem my_third_subitem=
  88. {
  89.   &my_fourth_subitem, /* NextItem, linked to the fourth subitem. */
  90.   50,              /* LeftEdge, 50 pixels out. */
  91.   25,              /* TopEdge, 25 lines down. */
  92.   150,             /* Width, 150 pixels wide. */
  93.   10,              /* Height, 10 lines high. */
  94.   ITEMTEXT|        /* Flags, render this item with text. */
  95.   ITEMENABLED|     /*        this item will be enabled. */
  96.   CHECKIT|         /*        it is an attribute item. */
  97.   HIGHCOMP,        /*        complement the colours when highlihted. */
  98.   0x00000001,      /* MutualExclude, mutualexclude the first subitem. */
  99.   (APTR) &my_third_text, /* ItemFill, pointer to the text. */
  100.   NULL,            /* SelectFill, nothing since we complement the col. */
  101.   0,               /* Command, no command-key sequence. */
  102.   NULL,            /* SubItem, ignored by Intuition. */
  103.   MENUNULL,        /* NextSelect, no items selected. */
  104. };
  105.  
  106.  
  107.  
  108. /*************************************************************************/
  109. /*                      S E C O N D   S U B I T E M                      */
  110. /*************************************************************************/
  111.  
  112. /* The text for the second subitem: */
  113. struct IntuiText my_second_text=
  114. {
  115.   2,          /* FrontPen, black. */
  116.   0,          /* BackPen, not used since JAM1. */
  117.   JAM1,       /* DrawMode, do not change the background. */
  118.   CHECKWIDTH, /* LeftEdge, CHECKWIDTH amount of pixels out. */
  119.               /* This will leave enough space for the check mark. */
  120.   1,          /* TopEdge, 1 line down. */
  121.   NULL,       /* TextAttr, default font. */
  122.   "Bold",     /* IText, the string. */
  123.   NULL        /* NextItem, no link to other IntuiText structures. */
  124. };
  125.  
  126. /* The MenuItem structure for the second subitem: */
  127. struct MenuItem my_second_subitem=
  128. {
  129.   &my_third_subitem, /* NextItem, linked to the third subitem. */
  130.   50,              /* LeftEdge, 50 pixels out. */
  131.   15,              /* TopEdge, 15 lines down. */
  132.   150,             /* Width, 150 pixels wide. */
  133.   10,              /* Height, 10 lines high. */
  134.   ITEMTEXT|        /* Flags, render this item with text. */
  135.   ITEMENABLED|     /*        this item will be enabled. */
  136.   CHECKIT|         /*        it is an attribute item. */
  137.   HIGHCOMP,        /*        complement the colours when highlihted. */
  138.   0x00000001,      /* MutualExclude, mutualexclude the first subitem. */
  139.   (APTR) &my_second_text, /* ItemFill, pointer to the text. */
  140.   NULL,            /* SelectFill, nothing since we complement the col. */
  141.   0,               /* Command, no command-key sequence. */
  142.   NULL,            /* SubItem, ignored by Intuition. */
  143.   MENUNULL,        /* NextSelect, no items selected. */
  144. };
  145.  
  146.  
  147.  
  148. /*************************************************************************/
  149. /*                       F I R S T   S U B I T E M                       */
  150. /*************************************************************************/
  151.  
  152. /* The text for the first subitem: */
  153. struct IntuiText my_first_text=
  154. {
  155.   2,          /* FrontPen, black. */
  156.   0,          /* BackPen, not used since JAM1. */
  157.   JAM1,       /* DrawMode, do not change the background. */
  158.   CHECKWIDTH, /* LeftEdge, CHECKWIDTH amount of pixels out. */
  159.               /* This will leave enough space for the check mark. */
  160.   1,          /* TopEdge, 1 line down. */
  161.   NULL,       /* TextAttr, default font. */
  162.   "Plain",    /* IText, the string. */
  163.   NULL        /* NextItem, no link to other IntuiText structures. */
  164. };
  165.  
  166. /* The MenuItem structure for the first subitem: */
  167. struct MenuItem my_first_subitem=
  168. {
  169.   &my_second_subitem, /* NextItem, linked to the second subitem. */
  170.   50,              /* LeftEdge, 50 pixels out. */
  171.   5,               /* TopEdge, 5 lines down. */
  172.   150,             /* Width, 150 pixels wide. */
  173.   10,              /* Height, 10 lines high. */
  174.   ITEMTEXT|        /* Flags, render this item with text. */
  175.   ITEMENABLED|     /*        this item will be enabled. */
  176.   CHECKIT|         /*        it is an attribute item. */
  177.   CHECKED|         /*        this item is initially selected. */
  178.   HIGHCOMP,        /*        complement the colours when highlihted. */
  179.   0xFFFFFFFE,      /* MutualExclude, mutualexclude all items except the */
  180.                    /*                first one. */
  181.   (APTR) &my_first_text, /* ItemFill, pointer to the text. */
  182.   NULL,            /* SelectFill, nothing since we complement the col. */
  183.   0,               /* Command, no command-key sequence. */
  184.   NULL,            /* SubItem, ignored by Intuition. */
  185.   MENUNULL,        /* NextSelect, no items selected. */
  186. };
  187.  
  188.  
  189.  
  190. /*************************************************************************/
  191. /*                       T H E   O N L Y   I T E M                       */
  192. /*************************************************************************/
  193.  
  194. /* The text for the item: */
  195. struct IntuiText my_text=
  196. {
  197.   2,          /* FrontPen, black. */
  198.   0,          /* BackPen, not used since JAM1. */
  199.   JAM1,       /* DrawMode, do not change the background. */
  200.   0,          /* LeftEdge, 0 pixels out. */
  201.               /* No space is needed for a check mark. */
  202.   1,          /* TopEdge, 1 line down. */
  203.   NULL,       /* TextAttr, default font. */
  204.   "Style",    /* IText, the string. */
  205.   NULL        /* NextItem, no link to other IntuiText structures. */
  206. };
  207.  
  208. /* The MenuItem structure for the item: */
  209. struct MenuItem my_item=
  210. {
  211.   NULL,              /* NextItem, no more items after this one. */
  212.   0,                 /* LeftEdge, 0 pixels out. */
  213.   0,                 /* TopEdge, 0 lines down. */
  214.   100,               /* Width, 100 pixels wide. */
  215.   10,                /* Height, 10 lines high. */
  216.   ITEMTEXT|          /* Flags, render this item with text. */
  217.   ITEMENABLED|       /*        this item will be enabled. */
  218.                      /*        it is an action item. (CHECKIT is not set) */
  219.   HIGHCOMP,          /*        complement the colours when highlihted. */
  220.   0,                 /* MutualExclude, no mutualexclude. */
  221.   (APTR) &my_text,   /* ItemFill, pointer to the text. */
  222.   NULL,              /* SelectFill, nothing since we complement the col. */
  223.   0,                 /* Command, no command-key sequence. */
  224.   &my_first_subitem, /* SubItem, pointer to the first subitem. */
  225.   MENUNULL,          /* NextSelect, no items selected. */
  226. };
  227.  
  228.  
  229.  
  230. /*************************************************************************/
  231. /*                              M E N U                                  */
  232. /*************************************************************************/
  233.  
  234. /* The Menu structure for the first (and only) menu: */
  235. struct Menu my_menu=
  236. {
  237.   NULL,        /* NextMenu, no more menu structures. */
  238.   0,           /* LeftEdge, left corner. */
  239.   0,           /* TopEdge, for the moment ignored by Intuition. */
  240.   50,          /* Width, 50 pixels wide. */
  241.   0,           /* Height, for the moment ignored by Intuition. */
  242.   MENUENABLED, /* Flags, this menu will be enabled. */
  243.   "Edit",      /* MenuName, the string. */
  244.   &my_item     /* FirstItem, pointer to the first (and only) item in */
  245.                /* the list. */
  246. };
  247.  
  248.  
  249.  
  250. /* Declare a pointer to a Window structure: */ 
  251. struct Window *my_window;
  252.  
  253. /* Declare and initialize your NewWindow structure: */
  254. struct NewWindow my_new_window=
  255. {
  256.   50,            /* LeftEdge    x position of the window. */
  257.   25,            /* TopEdge     y positio of the window. */
  258.   200,           /* Width       200 pixels wide. */
  259.   100,           /* Height      100 lines high. */
  260.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  261.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  262.   CLOSEWINDOW|   /* IDCMPFlags  The window will give us a message if the */
  263.                  /*             user has selected the Close window gad. */
  264.   MENUPICK,
  265.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  266.   WINDOWCLOSE|   /*             Close Gadget. */
  267.   WINDOWDRAG|    /*             Drag gadget. */
  268.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  269.   WINDOWSIZING|  /*             Sizing Gadget. */
  270.   ACTIVATE,      /*             The window should be Active when opened. */
  271.   NULL,          /* FirstGadget No Custom gadgets. */
  272.   NULL,          /* CheckMark   Use Intuition's default CheckMark. */
  273.   "Style Editor",/* Title       Title of the window. */
  274.   NULL,          /* Screen      Connected to the Workbench Screen. */
  275.   NULL,          /* BitMap      No Custom BitMap. */
  276.   80,            /* MinWidth    We will not allow the window to become */
  277.   30,            /* MinHeight   smaller than 80 x 30, and not bigger */
  278.   300,           /* MaxWidth    than 300 x 200. */
  279.   200,           /* MaxHeight */
  280.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  281. };
  282.  
  283.  
  284.  
  285. main()
  286. {
  287.   /* Boolean variable used for the while loop: */
  288.   BOOL close_me;
  289.  
  290.   /* Declare a variable in which we will store the IDCMP flag: */
  291.   ULONG class;
  292.   
  293.   /* If we recieve a MENUPICK event, the Code field of the message */
  294.   /* structure will contain the menu number of the first selected item. */
  295.   /* Declare a variable to store the Code value in, and an extra menu */
  296.   /* number variable: */
  297.   USHORT code, menu_number;
  298.   
  299.   /* Declare a MenuItem pointer: */
  300.   struct MenuItem *item;
  301.   
  302.   /* Declare a pointer to an IntuiMessage structure: */
  303.   struct IntuiMessage *my_message;
  304.  
  305.  
  306.  
  307.   /* Before we can use Intuition we need to open the Intuition Library: */
  308.   IntuitionBase = (struct IntuitionBase *)
  309.     OpenLibrary( "intuition.library", 0 );
  310.   
  311.   if( IntuitionBase == NULL )
  312.     exit(); /* Could NOT open the Intuition Library! */
  313.  
  314.  
  315.  
  316.   /* We will now try to open the window: */
  317.   my_window = (struct Window *) OpenWindow( &my_new_window );
  318.   
  319.   /* Have we opened the window succesfully? */
  320.   if(my_window == NULL)
  321.   {
  322.     /* Could NOT open the Window! */
  323.     
  324.     /* Close the Intuition Library since we have opened it: */
  325.     CloseLibrary( IntuitionBase );
  326.  
  327.     exit();  
  328.   }
  329.  
  330.  
  331.  
  332.   /* We have opened the window, and everything seems to be OK. */
  333.  
  334.  
  335.  
  336.   SetMenuStrip( my_window, &my_menu );
  337.   printf("Menustrip connected to window!\n");
  338.  
  339.  
  340.   close_me = FALSE;
  341.  
  342.   /* Stay in the while loop until the user has selected the Close window */
  343.   /* gadget: */
  344.   while( close_me == FALSE )
  345.   {
  346.     /* Wait until we have recieved a message: */
  347.     Wait( 1 << my_window->UserPort->mp_SigBit );
  348.  
  349.     /* As long as we collect messages sucessfully we stay in the loop: */
  350.     while(my_message=(struct IntuiMessage *) GetMsg( my_window->UserPort ))
  351.     {
  352.       /* After we have collected the message we can read it, and save any */
  353.       /* important values which we maybe want to check later: */
  354.       class = my_message->Class;
  355.       code = my_message->Code;
  356.  
  357.  
  358.       /* After we have read it we reply as fast as possible: */
  359.       /* REMEMBER! Do never try to read a message after you have replied! */
  360.       /* Some other process has maybe changed it. */
  361.       ReplyMsg( my_message );
  362.  
  363.       /* Check which IDCMP flag was sent: */
  364.       if( class == CLOSEWINDOW )
  365.         close_me=TRUE; /* The user selected the Close window gadget! */  
  366.  
  367.       if(class == MENUPICK)
  368.       {
  369.         printf("\nMenu pick!\n");
  370.         menu_number = code;
  371.         
  372.         while( menu_number != MENUNULL )
  373.         {
  374.           /* Get the address of the item: */
  375.           item = (struct MenuItem *) ItemAddress( &my_menu, menu_number );
  376.  
  377.  
  378.           /* Print out the menu number plus etc: */
  379.           printf("menu_number= %d\n", menu_number );
  380.           printf("MENUNUM = %d\n", MENUNUM(menu_number) );
  381.           printf("ITEMNUM = %d\n", ITEMNUM(menu_number) );
  382.           printf("SUBNUM  = %d\n", SUBNUM(menu_number) );
  383.  
  384.  
  385.           /* Get the following item's menu number: */
  386.           menu_number = item->NextSelect;
  387.         }
  388.       }
  389.     }
  390.   }
  391.  
  392.  
  393.  
  394.   printf("Menustrip removed from window!\n");
  395.   ClearMenuStrip( my_window );
  396.  
  397.  
  398.  
  399.   /* Close the window: */
  400.   CloseWindow( my_window );
  401.  
  402.  
  403.  
  404.   /* Close the Intuition Library since we have opened it: */
  405.   CloseLibrary( IntuitionBase );
  406.   
  407.   /* THE END */
  408. }
  409.